<?php 
if(!empty($_POST)){
	$ac = $_POST['ac'];
}
if (empty($ac)) {
	@include S_ROOT.'data/dataconfig.php';
	include atemplate('do_system');
}elseif ($ac == 'setting') {
	$limittime = trim($_POST['limittime']);
	if(!empty($_POST['limitip'])){
		$limitip = true;
	}else{
		$limitip = false;
	}
	$imageNum = trim($_POST['imageNum']);
	$uploadmax = intval($_POST['uploadmax']);
	$thumbwidth = intval($_POST['thumbwidth']);
	$thumbheight = intval($_POST['thumbheight']);
	$photowidth = intval($_POST['photowidth']);
	$photoheight = intval($_POST['photoheight']);

	$_config = array('limittime'=>$limittime,'limitip'=>$limitip,'imageNum'=>$imageNum,'uploadmax'=>$uploadmax,'thumbwidth'=>$thumbwidth,'thumbheight'=>$thumbheight,'photowidth'=>$photowidth,'photoheight'=>$photoheight);
	
	$configstr = "<?php\r\n\$_CONFIG=".var_export($_config,true).";\r\n?>";
	file_put_contents(S_ROOT.'data/dataconfig.php',$configstr);
	adminmessage('操作成功','index.php?do=system');
}elseif ($ac == 'password') {
	$old_password = trim($_POST['old_password']);
	$new_password = trim($_POST['password']);
	$new_password1 = trim($_POST['password1']);
//	print_r($_POST);
	if(!empty($old_password) && !empty($new_password) && $new_password == $new_password1) {
		$password = $db->result($db->query("select password from ".tname('admin')." where username = 'admin'"),0);
		var_dump($password);
		if(md5($old_password) == $password) {
			updatetable('admin',array('password'=>md5($new_password)),array('username'=>'admin'));
			adminmessage('修改密码成功');
		} else {
			adminmessage('原始密码不对');
		}
	}else{
		adminmessage('密码格式错误');
	}
}
?>